package work;

import java.util.Scanner;

public class test3 {
	public static final Object lock=new Object();
	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		System.out.println("请输入一个数字");
		int n=s.nextInt();
		for(int i=1;i<=n;i++){
			dibythree th=new dibythree(i);
			dibyfive  fi=new dibyfive(i);
			dibythreeandfive tf=new dibythreeandfive(i);
			dibyzero ze=new dibyzero(i);
			th.start();
			fi.start();
			tf.start();
			ze.start();
		}
	}
	static class dibythree extends Thread{
		private int i;

        public dibythree(int i) {
            this.i = i;
        }
		@Override
        public void run() {
            synchronized (lock) {
            	if(i%3==0&&i%5!=0){
            		System.out.print("fizz,");
            	}
            	lock.notify();
                try {
					lock.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}	
            } 
        }
	}
	static class dibyfive extends Thread{
		private int i;

        public dibyfive(int i) {
            this.i = i;
        }
		@Override
		 public void run() {
            synchronized (lock) {
            	if(i%5==0&&i%3!=0){
            		System.out.print("buzz,");
            	}
            	lock.notify();
                try {
					lock.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}	
            } 
        }
	}
	static class dibythreeandfive extends Thread{
		private int i;

        public dibythreeandfive(int i) {
            this.i = i;
        }
		@Override
		 public void run() {
            synchronized (lock) {
            	if(i%3==0&&i%5==0){
            		System.out.print("fizzbuzz,");
            	}
            	lock.notify();
                try {
					lock.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}	
            } 
        }
	}
	static class dibyzero extends Thread{
		 private int i;

	        public dibyzero(int i) {
	            this.i = i;
	        }
		@Override
		 public void run() {
            synchronized (lock) {
            	if(i%3!=0 && i%5!=0){
            		System.out.print(i+",");
            	}
            	lock.notify();
                try {
					lock.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}	
            } 
        }
	}

}
